<?

$domain1 = ucwords(str_replace("-",' ',$domain));
$domain2 = urlencode(str_replace("-",' ',$domain));

print "<h2>$domain1</h2>";

require_once("includes/spellchecker.class.php");
$correction = SpellChecker::Correct($domain1);

if (strcasecmp($correction,$domain1) != 0 && levenshtein($correction,$domain1) < 0.25*strlen($correction)) {
	$correction1 = urlencode(strtolower(str_replace(" ",'-',$correction)));
	print "<p>&middot; <i>Did you mean <b><a href=\"http://$correction1.portal.geographs.org/\">$correction</a></b>?</i></p>";
}


include($_SERVER['DOCUMENT_ROOT'].'/geograph/sphinxwrapper.class.php');
global $CONF;
$CONF['sphinx_host'] = "localhost";
$CONF['sphinx_port']= 3312;
$CONF['sphinx_index']= "portals";

        $q=trim($domain1);

        $sphinx = new sphinxwrapper("@(title,filters) $q");
	$sphinx->pageSize = $pgsize = 25;

	$pg = 1;
	$ids = $sphinx->returnIds($pg,'portals');

if (!empty($ids))  {

	global $c;

	$sql = array();
	$sql['columns'] = '*';
	$sql['tables'] = array();
	$sql['tables'][] = "portal";
	$sql['wheres'] = array();

	$sql['wheres'][] = "status_id = 1";
	$sql['wheres'][] = "public = 'Y'";
	$sql['wheres'][] = "portal_id IN (".implode(',',$ids).")";

	$sql['order'] = "portal_id DESC";

	$sql['limit'] = 25;

	$query = sqlMakeQuery($sql);

	$data = getAssoc($query);



	if ($data) {
		print "<div style=background-color:silver;padding:3px;>Possibly related portals... ";
		print "<ul class=\"list\">";
		foreach ($data as $id => $c) {

			print "<li>";
			print "<b><a href=\"http://".hec('domain').".portal.geographs.org/\" target=\"_blank\">".hec('title')."</a> <tt>http://".hec('domain').".portal.geographs.org/</tt></b>";
			print "</li>";
		}
		print "</ul>";
	
		print "</div>";
	} else {
		print "<p>No Portals to show at this time. <a href=\"http://www.geographs.org/portals/edit.php\">Create one</a>!</p>";
	}

}


print "<p>Here the results of a '<b>$domain1</b>' keyword search on Geograph Britain and Ireland, <b><a href=\"http://www.geograph.org.uk/search.php?searchtext=$domain2&amp;do=1\">View More Results Here</a></b></p>";

print "<iframe src=\"http://www.nearby.org.uk/geograph/search-service.php?q=$domain2\" width=\"750\" height=\"450\">Loading...</iframe>";

print "<p>Think this would make a good portal? <a href=\"http://www.geographs.org/portals/edit.php?q=$domain2\">Create a portal now</a>!</p>";


